"""Django电商平台 URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
import xadmin
from django.views.static import serve
from rest_framework.authtoken import views
from rest_framework.documentation import include_docs_urls

from Django电商平台.settings import MEDIA_ROOT
from app.goods.views import GoodListView, CategoryView
from rest_framework import routers

from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
)

from app.trade.views import ShoppingCartView, OrderInfoView
from app.user_operate.views import UserFavView, LeaveMessageView, UserAddressView
from app.users.views import VerifyView, RegisterView, UserView

router = routers.DefaultRouter()
router.register(r'goods', GoodListView)
# 添加分类展示
router.register(r'categories', CategoryView)
router.register(r'send_code', VerifyView, basename='code')
router.register(r'register', RegisterView, basename='register')
router.register(r'user', UserView, basename='user')
router.register(r'userfav', UserFavView, basename='userfav')
router.register(r'leavemessage', LeaveMessageView, basename='leavemessage')
router.register(r'address', UserAddressView, basename='address')
router.register(r'shopcart', ShoppingCartView, basename='shopcart')
router.register(r'order', OrderInfoView, basename='order')
urlpatterns = [
    # path('admin/', admin.site.urls),
    path('xadmin/', xadmin.site.urls),
    path(r'^ueditor/', include('DjangoUeditor.urls')),
    path('media/<path:path>', serve, {"document_root": MEDIA_ROOT}),
    url(r'^api-auth/', include('rest_framework.urls')),
    path('docs/', include_docs_urls(title='电商平台')),
    # path('goods/', GoodListView.as_view())
    # 通过该路由获取token信息
    # url(r'^api-token-auth/', views.obtain_auth_token),
    path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
]

urlpatterns += router.urls
